package pdf;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import org.omg.CORBA.Environment;

import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.xml.simpleparser.NewLineHandler;

public class PDF {

	List<Page> pages;
	
	public List<Page> getPages() {
		return new ArrayList<Page>(pages);
	}
	
	public PDF(String path) throws Exception {
		
		pages = new ArrayList<Page>();
		
		PdfReader reader = new PdfReader(new FileInputStream(new File(path)));
		
		PdfReaderContentParser parser = new PdfReaderContentParser(reader);
		
		for (int i = 1; i <= reader.getNumberOfPages(); i++) {
		
			Rectangle size = reader.getPageSize(i);
			
			List<Block> blocks = parser.processContent(i, new PDFTextListener()).getBlocks(size);
			
			pages.add(new Page(blocks, size));
		}
		
		reader.close();
		
	}
}
